package org.jeecg.modules.demo.com.kunpeng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.demo.com.kunpeng.entity.OaProjectCount;
import org.jeecg.modules.demo.com.kunpeng.entity.ProjectCount;
import org.jeecg.modules.demo.com.kunpeng.entity.dto.ProjectCountQueryDTO;
import org.jeecg.modules.demo.com.kunpeng.service.IProjectCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags="项目统计表")
@RestController
@RequestMapping("/com.kunpeng/projectCount")
@Slf4j
public class ProjectCountController {

    @Autowired
    private IProjectCountService projectCountService;

    /**
     * 分页查询
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "项目统计表-分页列表查询", notes = "项目统计表-分页列表查询")
    @PostMapping(value = "/list")
    public Result<IPage<ProjectCount>> queryPageList(@RequestBody ProjectCountQueryDTO projectCountQueryDTO,
                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        log.info("开始处理查询项目统计表请求...");
        Result<Page<ProjectCount>> result = new Result<Page<ProjectCount>>();
        Page<ProjectCount> pageList = new Page<ProjectCount>(pageNo, pageSize);
        pageList = projectCountService.projectCountList(pageList,projectCountQueryDTO);//通知公告消息
        if (pageList.getRecords().size() == 0) {
            return Result.error("没有符合条件的数据，请重新输入！");
        }
        log.info("查询当前页：" + pageList.getCurrent());
        log.info("查询当前页数量：" + pageList.getSize());
        log.info("查询结果数量：" + pageList.getRecords().size());
        log.info("数据总数：" + pageList.getTotal());
        result.setSuccess(true);
        result.setResult(pageList);
        return Result.ok(pageList);
    }

    /**
     * 分页查询
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "项目统计表-分页列表查询", notes = "项目统计表-分页列表查询")
    @PostMapping(value = "/listOaProject")
    public Result<IPage<OaProjectCount>> listOaProject(@RequestBody ProjectCountQueryDTO projectCountQueryDTO,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        log.info("开始处理查询项目统计表请求...");
        Result<Page<OaProjectCount>> result = new Result<Page<OaProjectCount>>();
        Page<OaProjectCount> pageList = new Page<OaProjectCount>(pageNo, pageSize);
        pageList = projectCountService.OaProjectCountList(pageList,projectCountQueryDTO);//通知公告消息
        if (pageList.getRecords().size() == 0) {
            return Result.error("没有符合条件的数据，请重新输入！");
        }
        log.info("查询当前页：" + pageList.getCurrent());
        log.info("查询当前页数量：" + pageList.getSize());
        log.info("查询结果数量：" + pageList.getRecords().size());
        log.info("数据总数：" + pageList.getTotal());
        result.setSuccess(true);
        result.setResult(pageList);
        return Result.ok(pageList);
    }
}
